package com.cq.hd.order.mapper;

import com.cq.hd.order.api.dto.*;
import com.cq.hd.order.api.vo.*;
import com.cq.hd.order.param.OrderNumSumParam;
import com.cq.hd.order.param.OrderStateUpdateParam;
import com.cq.hd.order.po.TbOrderPo;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.cq.hd.order.api.vo.AgentRankItemVo;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;

import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.util.List;

/**
 * <p>
 * 订单表 Mapper 接口
 * </p>
 *
 * @author mYunYu
 * @since 2023-12-13
 */
@Mapper
public interface TbOrderMapper extends BaseMapper<TbOrderPo> {

    List<AppOrderPageVo> listAppBuyOrderByDto(AppOrderPageDto appOrderPageDto);

    List<AppOrderPageVo> listAppAgentOrderByDto(AppOrderPageDto appOrderPageDto);

    // 自推订单
    List<AppOrderPageVo> listAppAgentSelfOrderByDto(AppOrderPageDto appOrderPageDto);

    // 团队订单
    List<AppOrderPageVo> listAppAgentTeamOrderByDto(AppOrderPageDto appOrderPageDto);

    List<AppOrderPageVo> listAppSellOrderByDto(AppOrderPageDto appOrderPageDto);

    AppOrderDetailVo getAppBuyOrderByDto(AppOrderDetailDto appOrderDetailDto);

    AppOrderDetailVo getAppAgentOrderByDto(AppOrderDetailDto appOrderDetailDto);

    AppOrderDetailVo getAppSellOrderByDto(AppOrderDetailDto appOrderDetailDto);

    List<AdminOrderPageVo> listAdminOrderByDto(AdminOrderPageDto adminOrderPageDto);

    List<AdminPointsOrderPageVo> listAdminPointsOrderByDto(AdminPointsOrderPageDto adminPointsOrderPageDto);

    List<AdminCommissionOrderPageVo> listAdminCommissionOrderByDto(AdminCommissionOrderPageDto adminCommissionOrderPageDto);

    List<MyPrizeOrderPageVo> pageMyPrizeOrder(MyPrizePageDto myPrizePageDto);

    AdminGroupOrderDetailVo detailAdminGroupOrder(@Param("orderId") Long orderId, @Param("orderType") Integer orderType);

    AdminEnrollOrderDetailVo detailAdminEnrollOrder(@Param("orderId") Long orderId, @Param("orderType") Integer orderType);

    AdminOrderDetailVo detailAdminOrder(@Param("orderId") Long orderId);

    List<AdminOrderCountVo> getOrderCount(AdminOrderCountDto adminOrderCountDto);

    List<OrderVo> listByDto(OrderDto orderDto);

    List<OrderAvatarVo> listAvatarByDto(OrderDto orderDto);

    Integer updateOrderState(OrderStateUpdateParam orderStateUpdateParam);

    SendOrderVo getSendOrderById(@Param("id") Long id);

    List<String> getLastAvatar(@Param("count") Integer count);

    Integer updateHfReqData(@Param("id") Long id, @Param("reqSeqId") String reqSeqId, @Param("reqDate") String reqDate);

    List<TbOrderPo> selectWaitCashbackOrders(@Param("startVerifyTime")String startVerifyTime, @Param("endVerifyTime")String endVerifyTime);

    Integer sumOrderNum(OrderNumSumParam param);

    int updateReturnAmt(@Param("orderId") Long orderId, @Param("returnAmt")BigDecimal returnAmt);

    void updateSettledCommissionAmt(@Param("orderId") Long orderId);

    void updateSettledCommissionAmt2(@Param("orderId") Long orderId, @Param("currentSettleCommissionAmt") BigDecimal currentSettleCommissionAmt);

    List<AgentRankItemVo> getAgentRank(ActiveRankQueryDto activeRankQueryDto);

    BigDecimal selectEstimateCommissionStatistics(@Param("agentId") Long agentId, @Param("startTime")LocalDateTime startTime, @Param("endTime") LocalDateTime endTime);

    // 查询积分待结算的订单【下单用户积分结算】
    List<OrderPointsVo> selectUserUnSettlePointsOrders();

    // 查询积分待结算的订单【经纪人积分结算】
    List<OrderPointsVo> selectAgentUnSettlePointsOrders();

    int updatePointsSettleState(@Param("orderId") Long orderId, @Param("field") String field);

    // 子订单结算，将 agent_points_settle_state 设置为 1
    void setAgentPointsSettleState(@Param("orderId") Long orderId);
}
